﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CCMD_Console
{
    class Program
    {
        private static string OcrFunc(string imgfileName) // 参数为包含文本的图片文件名
        {
          //  var langs = MODI.MiLANGUAGES.miLANG_ENGLISH;
            var langs = MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED;
            // MODI.MiLANGUAGES.miLANG_CHINESE_SIMPLIFIED; 中文含英文
            // MODI.MiLANGUAGES.miLANG_JAPANESE; 日文含英文

            var doc = new MODI.Document();
            var image = default(MODI.Image);
            var layout = default(MODI.Layout);

            try
            {
                doc.Create(imgfileName);
                doc.OCR(langs, true, true);
                var sb = new StringBuilder();

                for (int i = 0; i < doc.Images.Count; i++)
                {
                    image = (MODI.Image)doc.Images[i];
                    layout = image.Layout;
                    sb.AppendLine(string.Format("{0}, {1}", i, layout.Text));
                }
                doc.Close(false);
                return sb.ToString();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
                return string.Empty;
            }
            finally
            {
                layout = null;
                image = null;
                doc = null;
            }
        }
        static void Main(string[] args)
        {
            string imgfileName = "D:\\wenzi.png";
            string res = OcrFunc(imgfileName);
            Console.WriteLine(res);
        }
    }
}
